package com.qing.search

import org.apache.spark.{SparkConf, SparkContext}
import spark.{Response, Route, Spark}

/**
  * Created by wuliao on 2017/8/17.
  */
object TestSearchServer {
  def main(args: Array[String]): Unit = {
    Spark.post("/search/:page", new Route {
      override def handle(request: spark.Request, response: Response): String = {
        val begin = System.currentTimeMillis()
        val map = request.queryMap().toMap
        val rdd = new LucenePageRDD(sc,map)
        rdd.collect().toBuffer+"..."+(System.currentTimeMillis() - begin)+"..."

      }
    })
  }

  val sc = {
    val path = "hdfs://127.0.0.1:9000/data/index"
    val conf = new SparkConf()
      .setAppName("hello")
      .set("lucene.path", path)
      .set("lucene.node", "10")
//      .setMaster("spark://175.102.18.112:7077")
//      .setJars(Array("file:///mnt/disk/jar/spark-lucene-1.0-SNAPSHOT-jar-with-dependencies.jar"))
          .setMaster("local")
    new SparkContext(conf)
  }



}
